<!doctype html>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<html>
<head>
<meta charset="utf-8">
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/global.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/layout.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/easyui.css">
<script src="${basePath }commonJs/jquery.min.js"></script>
<script src="${basePath }commonJs/jquery.easyui.min.js"></script>
<script src="${basePath }commonJs/jt_normal.js"></script>
<script src="${basePath }commonJs/jt_select.js"></script>
<script src="${basePath }commonJs/tags/My97DatePicker/WdatePicker.js"></script>

<script src="${basePath }commonJs/promotion/wolf_common.js"></script>
<script src="${basePath }commonJs/promotion/wolf_validation.js"></script>
<title>房间管理</title>
</head>

<script type="text/javascript">
var userAll = ${userAll};
var batchId = "${batchId}";
var condList=[];
$(document).ready(function(){
	
	/**编辑时 初始化数据*/
	editLoad();
	/**编辑抽样数量*/
	readTime(batchId);
});
/**
 * 关联销售 绑定select标签
 */
function refSale(v){
	var result = "全部";
	if(wolf.isNotNull(v)){
		if(wolf.isNotNull(userAll) && userAll.length > 0){
			wolf.data_foreach(userAll, function(i,user){
				if(v == user.pkUsrId){
					alert(v + "-" +user.pkUsrId);
					
					result = user.usrName;
				}
			});
		}
	}
	return result;
}
/**编辑加载内容*/
function editLoad(){
	if(wolf.isNotNull(condList) && condList.length > 0){
		$("#_v2").hide();
		$("#_v1").show();
		$("#_v1v").show();
		$("#_v2v").hide();
		
		wolf.data_foreach(condList, function(i,obj){
			var objContext = obj.condDetail;
			
			if(wolf.isNotNull(obj.profileType)){
				var contextArry = objContext.split("|");
				
				/* if(wolf.isNotNull(contextArry) && contextArry.length > 0){ */
					
					if(obj.profileType == 1){
						/* <!-- 1：未激活 2：有效  3：过期  4：停卡 5：新建 --> */
						var falg = false;
						var status = contextArry[0];
						var hy = "会员状态:";
						if(wolf.isNotNull(status))falg=true;
						hy += wolf.isNotNull(status)?"全部":status==1?"未激活":status==2?"有效":status==3?"过期":status==4?"停卡":"全部";
						
						hy +="\n";
						if(wolf.isNotNull(isSplit(contextArry[1],",",0)) && wolf.isNotNull(isSplit(contextArry[1],",",1))){
							hy +="会员生日："+ isSplit(contextArry[1],",",0) + "至" + isSplit(contextArry[1],",",1);
							falg = true;
						}else{
							hy +="会员生日：无条件";
						}
						hy +="\n";
						if(wolf.isNotNull(isSplit(contextArry[2],",",0)) && wolf.isNotNull(isSplit(contextArry[2],",",1))){
							hy +="入会日期："+ isSplit(contextArry[2],",",0) + "至" + isSplit(contextArry[2],",",1);
							falg = true;
						}else{
							hy +="入会日期：无条件";
						}
						hy +="\n";
						if(wolf.isNotNull(isSplit(contextArry[3],",",0)) && wolf.isNotNull(isSplit(contextArry[3],",",1))){
							hy +="失效日期："+ isSplit(contextArry[3],",",0) + "至" + isSplit(contextArry[3],",",1);
							falg = true;
						}else{
							hy +="失效日期：无条件";
						}
						hy +="\n";
						if(wolf.isNotNull(refSale(contextArry[4]))){
							hy +="销售："+ refSale(contextArry[4]);
							falg = true;
						}else{
							hy +="销售：全部";
						}
						hy +="\n";
						$("#_v1v1d").show();
						$("#_v1v1").text(falg ? hy.substr(0,6)+"..." : "无");
						$("#_v1v1").attr("title",hy);
						$("#_v1v1d").show();
						return;
					}else if(obj.profileType == 2){
						var fhy="";
						var falg = false;
						if(wolf.isNotNull(isSplit(contextArry[0],",",0)) && wolf.isNotNull(isSplit(contextArry[0],",",1))){
							fhy +="非会员生日："+ isSplit(contextArry[0],",",0) + "至" + isSplit(contextArry[0],",",1);
							falg = true;
						}else{
							fhy +="非会员生日：无条件";
						}
						fhy +="\n";
						if(wolf.isNotNull(isSplit(contextArry[1],",",0)) && wolf.isNotNull(isSplit(contextArry[1],",",1))){
							fhy +="购票日期："+ isSplit(contextArry[1],",",0) + "至" + isSplit(contextArry[1],",",1);
							falg = true;
						}else{
							fhy +="购票日期：无条件";
						}
						$("#_v1v2d").show();
						$("#_v1v2").text(falg ? fhy.substr(0,6)+"...":"无");
						$("#_v1v2").attr("title",fhy);
						return;
					}else if(obj.profileType == 3){
						var fk = "";
						var falg = false;
						if(wolf.isNotNull(isSplit(contextArry[0],",",0)) && wolf.isNotNull(isSplit(contextArry[0],",",1))){
							fk +="访问日期："+ isSplit(contextArry[0],",",0) + "至" + isSplit(contextArry[0],",",1);
							falg = true;
						}else{
							fk +="访问日期：无条件";
						}
						fk +="\n";
						if(wolf.isNotNull(refSale(contextArry[1]))){
							fk +="销售："+ refSale(contextArry[1]);
							falg = true;
						}else{
							fk +="销售：全部";
						}
						$("#_v1v3d").show();
						$("#_v1v3").text(falg ? fk.substr(0,6)+"...":"无");
						$("#_v1v3").attr("title",fk);
						return;
					}else if(obj.profileType == 4){
						var pdlx = "";
						var falg = false;
						if(wolf.isNotNull(isSplit(contextArry[0],",",0)) && wolf.isNotNull(isSplit(contextArry[0],",",1))){
							pdlx +="举办日期："+ isSplit(contextArry[0],",",0) + "至" + isSplit(contextArry[0],",",1);
							falg = true;
						}else{
							pdlx +="举办日期：无条件";
						}
						$("#_v1v4d").show();
						$("#_v1v4").text(falg ? pdlx.substr(0,6)+"...":"无");
						$("#_v1v4").attr("title",pdlx);
						return;
					}
				/* } */
				
			}
		});
	}else if(wolf.isNotNull(batchId)){
		$("#_v1").hide();
		$("#_v2").show();
		$("#_v1v").hide();
		$("#_v2v").show();
		
		dPage();
	}
}

/**分割字符串*/
function isSplit(context,spes,index){
	if(wolf.isNotNull(context)){
		var arry = context.split(spes);
		var leng = arry.length;
		if(wolf.isNotNull(arry) && leng > 0){
			var i = (index >= leng?index-1:index);
			return arry[i];
		}else{
			return "";
		}
	}
	return "";
}




function readTime(batchId){
	if(wolf.isNotNull(batchId)){
		$.ajax({ 
			url: "${basePath}sms/batch/readTimeCount.shtml",
			data:"fkBatchId="+batchId,
			async:false,
			dataType: 'json',
			type:'POST',
			success: function(data){
				$("#_batch_cond").text("");
				$("#_batch_cond").text("预计发送个数为："+data);
	      	}
		});
	}else{
		$("#_batch_cond").text("");
		$("#_batch_cond").text("预计发送数量：请先保存后查看数量");
	}
	
}
function dPage(){
	
	$("#fkBatchId").val(batchId);
	var form = $("#form_phone_d"); 
    var pagebean = new PageBean(form);
    pagebean.setTableId("form_phone_table");
    pagebean.setCallback(dPageCall);
    pagebean.setFootId("form_phone_page");
    setPagebeanObj(pagebean); 
    pagebean.doPage();
    
    
}
function dPageCall(data,param){
	if(wolf.isNotNull(data)){
		wolf.data_foreach(data, function(i,obj){
			var tr = "<tr>"+
		                "<td>"+obj.destPhone+"</td>"+
		           	 "</tr>";
		    $("#form_phone_table").append(tr);
		});
	};
	/**显示分页数量*/
    $("#form_phone_count").text("");
    $("#form_phone_count").text("发送数量:"+param.totalRecord);
}
</script>
<c:if test="${!empty condList }">
	<script type="text/javascript">
		condList =${condList};
	</script>
</c:if>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
            <shiro:hasPermission name="sms/batch/home.shtml">
            	<li class="content_hover"><a href="${basePath}sms/batch/home.shtml"><i class="nav_icon_v"></i><br>短信发送</a></li>
        	</shiro:hasPermission>
        </ul>
    </div>
    <div class="content_r mt10">
    	<!---- 内容 --->
    	
        <div class="file_single_dl fixed mt20">
	        	<dl class=" w370 fl">
	            	<dd><label>所属门店：</label>${entity.branName }
	                </dd>
	            	<dd><label>发送内容：</label><span class="textare_m">${entity.context }</span></dd>
	                <dd><label>预期发送时间：</label>${entity.planTimeStr }</dd>
	            </dl>
            <div class="duax_x ml30">
                <ul class="ul_radio fixed" >
                    <li id="_v1"> 现有档案中抽取</li>
                    <li id="_v2"> 手工录入</li>
                </ul>
                <ul>
                    <li id="_v1v">
                    	<table class="table">
                        	<tr>
                                <th>档案类型</th>
                                <th>抽取条件</th>
                            </tr>
                            <tr id="_v1v1d" style="display: none;">
                            	<td>会员</td>
                                <td class="lv" id="_v1v1" >无</td>
                            </tr>
                            <tr id="_v1v2d" style="display: none;">
                            	<td>非会员</td>
                                <td class="lv" id="_v1v2"></td>
                            </tr>
                            <tr id="_v1v3d" style="display: none;">
                            	<td>访客</td>
                                <td class="lv" id="_v1v3"></td>
                            </tr>
                            <tr id="_v1v4d" style="display: none;">
                            	<td>派对联系人</td>
                                <td class="lv" id="_v1v4"></td>
                            </tr>
                        </table>
                        <!----翻页----->
                        <p class="m10" id="_batch_cond">预计发送数量：0</p>
                    </li>
                    <li id="_v2v">
                    	<table class="table" id="form_phone_table" >
                        	<tr>
                                <th>电话号码</th>
                            </tr>
                            
                        </table>
                        <!----翻页----->
                        <div class="page fr m10" id="form_phone_page">
                        </div>
                        <!----翻页----->
                        <p class="mt10" id="form_phone_count">发送数量：0</p>
                    </li>
                    <form action="${basePath }sms/batch/searchSmsBox.shtml" id="form_phone_d">
				    	<input type="hidden" name="fkBatchId" id="fkBatchId" value="">
				    	<input type="hidden" name="pageNo" value="1">
				    	<input type="hidden" name="pageSize" value="6">
				    </form>
                </ul>
        	</div>
        </div>
        <!----底部按钮----->
        <div class="btm_btn mt50">
                <dl>
                    <dd><input type="button" class="btn" value="返回" onclick="javascript:window.location.href='${basePath}sms/batch/home.shtml'"></dd>
                </dl>
        </div>
        <!----底部按钮----->
        <!---- 内容 --->
    </div>
</div>


</body>
</html>
